package practice1_100;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Practice17 {
    List<String> listAll =new ArrayList<>();
    Map<Character,String > map =new HashMap<>();

    public List<String> letterCombinations(String digits) {
        if(digits.length()==0) return new ArrayList<>();

        map.put('2',"abc");
        map.put('3',"def");
        map.put('4',"ghi");
        map.put('5',"jkl");
        map.put('6',"mno");
        map.put('7',"pqrs");
        map.put('8',"tuv");
        map.put('9',"wxyz");
        loopAdd(digits,0,"");
        return listAll;
    }
    public void  loopAdd(String str,int index,String s){
        if(index==str.length()){
            listAll.add(s);
            return;//这里添加return，可以终止方法
        }

        for (int i=0;i<map.get(str.charAt(index)).length();i++){
            loopAdd(str,index+1,s+map.get(str.charAt(index)).charAt(i));
        }
    }

    public static void main(String[] args) {
        Practice17 practice17=new Practice17();
        practice17.letterCombinations("2345678");
    }
}
